package com.jz.netthings.appengine.support;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jz.netthings.appengine.baseData.MachineData;
import com.jz.netthings.appengine.baseData.ProviderData;
import com.jz.netthings.netty.protocol.bean.ZxdcMsgPacket;

import java.util.HashMap;

public class BeanSupport {

    public static ZxdcMsgPacket loadToAllotMsg(ProviderData providerData, String call){
        ZxdcMsgPacket allotMsg = new ZxdcMsgPacket();
        allotMsg.setCmd("plasma_donor_status_changed");
        allotMsg.setHasResponse(false);
        allotMsg.setLevel(3);
        HashMap<String, Object> values = new HashMap<String, Object>();
        values.put("pcode", providerData.getProviderNo());
        values.put("info", JSON.toJSONString(providerData, SerializerFeature.PrettyFormat));
        if (call != null && !"".equals(call)){
            values.put("call", call);
        }
        allotMsg.setValues(values);

        return allotMsg;
    }
    public static ZxdcMsgPacket loadToAllotMsg(MachineData machine){
        ZxdcMsgPacket packet = new ZxdcMsgPacket();
        packet.setCmd("machine_status_changed");
        packet.setHasResponse(false);
        packet.setLevel(3);
        HashMap<String, Object>  values = new HashMap<String, Object>();
        values.put("mcode", machine.getCode());
        values.put("info", JSON.toJSONString(machine, SerializerFeature.PrettyFormat));
        packet.setValues(values);

        return packet;
    }
}
